package net.csdn.business.discuss.common.interceptor.impl;


import lombok.extern.slf4j.Slf4j;
import net.csdn.business.discuss.common.constant.CommonConstants;
import net.csdn.business.discuss.common.context.AuthContextHolder;
import net.csdn.business.discuss.common.context.model.AuthContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @ClassName GitCodeInterceptor
 * @Description 透传华为相关token
 * @Author zhangyl
 * @Date 2023/7/14 09:44
 */
@Slf4j
public class GitCodeInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String x_auth_token=request.getHeader(CommonConstants.X_AUTH_TOKEN);
        String x_uid=request.getHeader(CommonConstants.X_UID);
        String x_username=request.getHeader(CommonConstants.X_USERNAME);
        String x_iam_id=request.getHeader(CommonConstants.X_IAM_ID);
        String x_code_art_id=request.getHeader(CommonConstants.X_CODE_ART_ID);
        log.info("git code  request header info: x_uid:{},x_username:{},x_iam_id:{},x_code_art_id:{}",x_uid,x_username,x_iam_id,x_code_art_id);
        AuthContext authContext=new AuthContext(x_auth_token, x_uid, x_username, x_iam_id, x_code_art_id);
        AuthContextHolder.setContext(authContext);
        return true;
    }

}